#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
long long n,ans=-1,a[205],dp[205][205][205];
int main()
{
	freopen("shung.in","r",stdin);
	freopen("shung.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(long long i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	a[n+1]=0;
	for(long long i=0;i<=n;i++)
	{
		for(long long j=0;j<=i;j++)
		{
			for(long long k=0;k<=max(i-1,0ll);k++)
			{
				if(j!=k||j==0)
				{
					long long id=j,id2=k,cnt=0; 
					for(long long l=i+1;l<=n+1;l++)
					{
						if(a[l]>a[id]||!id)
						{
							id=l;
						}
						if(i+1<=l-1)
						{
							if(a[l-1]<a[id2]||!id2)
							{
								id2=l-1;
								cnt++;
							}
						}
						dp[l][id][id2]=max(dp[l][id][id2],dp[i][j][k]+cnt+(id==l));
						id=j;
					}		
				}	
			}
		}
	} 
	for(long long i=0;i<=n+1;i++)
	{
		for(long long j=0;j<=n;j++)
		{
			ans=max(ans,dp[n+1][i][j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}
